type Error = Box<dyn std::error::Error>;
type Result<T> = std::result::Result<T, Error>;

pub struct ByteBucketBuffer {
    pub buf: [u8; 512],
    pub pos: usize,
}

impl ByteBucketBuffer {
    pub fn new() -> Self {
        Self {
            buf: [0; 512],
            pos: 0,
        }
    }

    fn pos(&self) -> usize {
        self.pos
    }

    fn step(&mut self, step: usize) {
        self.pos += step;
    }

    fn seek(&mut self, pos: usize) {
        self.pos = pos;
    }

    fn read(&mut self, pos: usize) -> Result<u8> {
        if pos >= 512 {
            return Err("end of buffer".into());
        }
        let res = self.buf[pos];
        self.pos += 1;
        Ok(res)
    }
}
